/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package service;

import graphviewer.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;

/**
 *
 * @author Sabitov Artem
 * @date 02.10.2013
 */
public class ServiceInfo extends JPanel {
	private int posX = 4;
	private int posY = 0;
	private int step = 14;
	private String sDbg;
	private ArrayList<String> debugBuffer;
	
	private void getDebugInfoOff() {
		sDbg = "off";
		debugBuffer.clear();
		debugBuffer = new ArrayList<>();
		debugBuffer.add("General:");
		debugBuffer.add("debug: " + sDbg); // состояние дебагера
		debugBuffer.add("node count: " + Parser.nodeCount); // количество нодов
		debugBuffer.add("graph count: " + Parser.graphCount); // количество графов
		debugBuffer.add("------------------------------------");
	}
	private void getDebugInfo() {
		sDbg = "on";
		debugBuffer.clear();
		debugBuffer = new ArrayList<>();
		debugBuffer.add("General:");
		debugBuffer.add("debug: " + sDbg); // состояние дебагера
		debugBuffer.add("node count: " + Parser.nodeCount); // количество нодов
		debugBuffer.add("graph count: " + Parser.graphCount); // количество графов
		debugBuffer.add("----------------------------------------------------------");
		
		debugBuffer.add("Calculative:");
		debugBuffer.add("processing: " + GraphCalculate.getStateProcessing());
		debugBuffer.add("distance force attractive: " + GraphCalculate.MIN_DISTANCE_ATTRACTIVE);
		debugBuffer.add("distance force repulsive: " + GraphCalculate.MAX_DISTANCE_REPULSIVE);
		debugBuffer.add("distance force resultant: " + (GraphCalculate.MIN_DISTANCE_ATTRACTIVE - GraphCalculate.MAX_DISTANCE_REPULSIVE));
		debugBuffer.add("force factor attractive: " + GraphCalculate.FORCE_FACTOR_ATTRACTIVE);
		debugBuffer.add("force factor repulsive: " + GraphCalculate.FORCE_FACTOR_REPULSIVE);
		debugBuffer.add("delta time to calculate: " + GraphCalculate.DELTA_TIME + "ms");
		debugBuffer.add("delay in calculation: " + (GraphCalculate.SLEEP_TIME / (GraphCalculate.TIME_FACTOR*10)) + "ms");
		debugBuffer.add("time factor: " + GraphCalculate.TIME_FACTOR);
		debugBuffer.add("sleep time: " + GraphCalculate.SLEEP_TIME);
		debugBuffer.add("----------------------------------------------------------");
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		Font font = new Font("Arial", 0, 11); 
		g2d.setFont(font);
		for(int i = 0; i < debugBuffer.size(); i++) {
			g2d.drawString(debugBuffer.get(i), posX, posY + step + step * i);
			g2d.drawLine(posX, posY + step + step * i + 3, posX + GraphViewer.FRAME_WIDTH / 4, posY + step + step * i + 3);
		}
	}
	
	public ServiceInfo() {
		debugBuffer = new ArrayList<>();
		if(Service.getServiceState()) {
			getDebugInfo();
		} else getDebugInfoOff();
		setBackground(Color.BLUE);
		setOpaque(Service.getStateDebugComponent());
		setBounds(0, 0, 236, 246);
	}
	
	public void update() {
		if(Service.getServiceState()) {
			this.getDebugInfo();
		} else getDebugInfoOff();
		repaint();
	}
}

